// pages/user/userWallet/index.js
import urls from '../../../requestUrl'
import request from '../../../baseRequest'

let h;
let w;
wx.getSystemInfo({
    success: function(res) {
        console.log(res.windowHeight, res.screenHeight)
        h = res.windowHeight - 30
        w = res.windowWidth
    },
})

Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabCurrent: 0,
        swiperCurrent: 0,
        swiperHeight: h,
        scrollHeight: h - 200,
        scrollWidth: w - 30,
        incomeInfo: {},
        incomeList: [],
        withdrawList: [],
        companyIncomeInfo: [],
        companyIncomeList: [],
        companyWithdrawList: []
    },

    handleTabChange(e) {
        console.log(e)
        this.setData({
            swiperCurrent: e.detail.key
        })
    },

    handleSwiperChange(e) {
        console.log(e)
        this.setData({
            tabCurrent: e.detail.current
        })
    },

    /**获取用户收益列表 */
    getUserIncomeList() {
        let url = `${urls.userWallet.getIncomList}/${this.data.openid}`
        request.getRequest(url, {}, (res) => {
            this.setData({
                incomeInfo: res.incomeInfo,
                incomeList: res.incomeList,
                withdrawList: res.withdrawList
            })
        }, () => {})
    },

    /**获取用户积分列表 */
    getIntegralList() {
        let url = `${urls.userWallet.getIntegralList}/${this.data.openid}`
        request.getRequest(url, {}, (res) => {
            this.setData({
                integralInfo: res.integralInfo,
                integralList: res.integralList
            })
        }, () => {})
    },

    /**获取公司收益列表 */
    getCompanyIncomeList() {
        let url = `${urls.userWallet.getCompanyIncomList}/${this.data.openid}`
        request.getRequest(url, {}, (res) => {
            this.setData({
                companyIncomeInfo: res.incomeInfo,
                companyIncomeList: res.incomeList,
                companyWithdrawList: res.withdrawList
            })
        }, () => {})
    },

    /**获取公司积分列表 */
    getCompanyIntegralList() {
        let url = `${urls.userWallet.getCompanyIntegralList}/${this.data.openid}`
        request.getRequest(url, {}, (res) => {
            this.setData({
                companyIntegralInfo: res.integralInfo,
                companyIntegralList: res.integralList
            })
        }, () => {})
    },


    /**提现 */
    toWithdraw() {
        wx.navigateTo({
            url: '/pages/user/userWithdraw/index?type=1',
        })
    },

    /**提现公司收益 */
    toWithdrawCompany() {
        wx.navigateTo({
            url: '/pages/user/userWithdraw/index?type=2',
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.data.openid = getApp().getUserOpenid()
        let userInfo = getApp().globalData.userInfo
        this.setData({
            isMananger: userInfo.isManager === '2'
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        this.getUserIncomeList()
        this.getIntegralList()
        this.getCompanyIncomeList()
        this.getCompanyIntegralList()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    // onShareAppMessage: function() {

    // }
})